package com.leihao.product.controller;

import com.github.pagehelper.PageInfo;
import com.leihao.common.core.domain.R;
import com.leihao.product.domian.*;
import com.leihao.product.domian.listRequest.TypeListRequest;
import com.leihao.product.service.ProductTypeService;
import com.leihao.system.api.domain.SysFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("productType")
@Api(tags = "商品分类管理")
public class ProductTypeController {

    @Autowired
    private ProductTypeService productTypeService;

    /**
     * 查询所有一级商品分类
     * @param typeListRequest
     * @return
     */
    @PostMapping("/findFirstList")
    @ApiOperation(value = "查询所有一级商品分类")
    public R<PageInfo<ProductType>> findFirstList(@Validated @RequestBody TypeListRequest typeListRequest)
    {
        PageInfo<ProductType> firstList = productTypeService.findFirstList(typeListRequest);
        return R.ok(firstList);
    }
    /**
     * 级联查询
     * @return
     */
    @GetMapping("/findLinkageList")
    @ApiOperation(value = "级联查询")
    public R<List<ProductTypeLinkage>> findLinkageList()
    {
        List<ProductTypeLinkage> linkageList = productTypeService.findLinkageList();
        return R.ok(linkageList);
    }

    /**
     * 查询所有一级分类
     * @param
     * @return
     */
    @GetMapping("/selectFirstList")
    @ApiOperation(value = "查询所有一级分类")
    public R<List<FirstProductType>> selectFirstList()
    {
        List<FirstProductType> firstList = productTypeService.selectFirstList();
        return R.ok(firstList);
    }
    /**
     * 查询上一级的列表查询条件实体
     * @param
     * @return
     */
    @GetMapping("/getUpList/{parenId}")
    @ApiOperation(value = "查询上一级的列表查询条件实体")
    @ApiImplicitParam(name = "parenId",value = "父级ID",required = true,dataType = "Integer")
    public R<TypeListRequest> getUpList(@PathVariable Integer parenId)
    {
        TypeListRequest typeListRequest = productTypeService.getUpList(parenId);
        return R.ok(typeListRequest);
    }
    /**
     * 根据编号查询商品分类信息
     * @param productId
     * @return
     */
    @GetMapping("/findById/{productId}")
    @ApiOperation(value = "根据编号查询商品分类信息")
    public R<ProductType> findById(@PathVariable Integer productId)
    {
        ProductType productType = productTypeService.findById(productId);
        return R.ok(productType);
    }
    /**
     * 逻辑删除
     * @param productTypeId
     * @return
     */
    @DeleteMapping("/delete/{productTypeId}")
    @ApiOperation(value = "逻辑删除")
    @ApiImplicitParam(name = "productTypeId",value = "主键ID",required = true,dataType = "Integer")
    public R delete(@PathVariable Integer productTypeId)
    {
        productTypeService.delete(productTypeId);
        return R.ok(null,"删除成功");
    }
    /**
     * 修改商品分类
     * @param productType
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改商品分类")
    public R update(@RequestBody ProductType productType)
    {
        productTypeService.update(productType);
        return R.ok(null,"修改成功");
    }
    /**
     * 添加商品分类
     * @param productType
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加商品分类")
    public R add(@Validated @RequestBody ProductType productType)
    {
        productTypeService.add(productType);
        return R.ok(null,"添加成功");
    }


}
